////////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2010 galaxy.org
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

package org.galaxy.richflex.utils
{
	import mx.utils.ObjectUtil;

	/**
	 * Object helper class. There are some useful functions used for object operations.
	 * 
	 * @author Cheng Liang
	 * 
	 * @version 0.0.1 create 2010-9-6;
	 * @version 0.0.1a renamed from <code>ObjectUtils</code> to <code>ObjectHelper</code> 2010-9-27;
	 */
	public class ObjectHelper
	{
		/**
		 * Checks if object a and object b are equal.
		 * 
		 * @param a object
		 * @param b object
		 * @param properties properties list, a string array which contains property names
		 * in both objects
		 * 
		 * @return true if a and b are equal
		 */
		public static function equals(a : Object, b : Object, properties : Array) : Boolean
		{
			if((a && !b) || (!a && b)) {
				return false;
			} else if(!a && !b) {
				return true;
			} else {
				if(a == b) {
					return true;
				} else {
					if(properties == null || properties.length == 0) {
						return a == b;
					} else {
						for each(var prop : String in properties) {
							if(ObjectUtil.compare(a[prop], b[prop]) != 0) {
								return false;
							}
						}
						return true;
					}
				}
			}
			return false;
		}
		
		public function ObjectHelper()
		{
		}
		
	}
}